#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from model import ClassM

class setClassHandler(webapp.RequestHandler):
    def get(self):
        lectureKey = self.request.get("lectureKey")
#        if index is None:
#            index = -1
        if lectureKey:
            result = ClassM.startClass(lectureKey)
            if isinstance(result, basestring): #Error
                self.redirect("/error?msg="+result)
            elif result:
                self.redirect("/prof?lectureKey=" + lectureKey)
        else:
            pass

application = webapp.WSGIApplication([(r'.*', setClassHandler)],debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()